package cn.openea.perpartner.meily.web.mapper;

import cn.openea.perpartner.meily.web.entity.RevenueRecordsIns;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * meily_revenue_records_ins 区域服务商收入记录
 *
 * @author ysk
 * @email zane_ysk@qq.com
 * @date 2023-03-22 10:51:50
 */
@Mapper
public interface RevenueRecordsInsMapper extends BaseMapper<RevenueRecordsIns> {

    /**
     * 获取上个月的收益记录
     *
     * @return
     */
    @Select("select * from meily_revenue_records_ins where DATE_FORMAT(create_time, '%Y%m') = DATE_FORMAT(date_sub(CURDATE(), interval 1 month), '%Y%m');")
//  某月  @Select("select * from meily_revenue_records_ins where DATE_FORMAT(create_time, '%Y%m') = DATE_FORMAT(date_sub('2023-04-30 23:55:22', interval 1 month), '%Y%m');")
    List<RevenueRecordsIns> getLastMonthRecordsList();

    @Select("SELECT SUM(CAST(accumulated_income AS DECIMAL(10,2))) FROM meily_revenue_records_ins WHERE DATE_FORMAT(settlement_date,'%Y-%m') = #{timePeriod}")
    BigDecimal countCumulative(@Param("timePeriod") String timePeriod);
}
